home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / pcrsep89.arc / FIRE.BAS < prev    next >
BASIC Source File  |  1990-03-21  |  2KB  |  65 lines

  1. '  This Quick Basic program simulates a forest fire.
  2. '  Save as:     FIRE.BAS
  3. '  Compile:     BC FIRE;
  4. '               LINK FIRE CA;
  5.  
  6. DEFINT A-Z
  7. ' $Include: 'CA.BI'
  8.  
  9. CONST AFIRE = 12
  10. CONST CHARRED = 6
  11. CONST UNBURNED = 1
  12. COMMON SHARED prob!
  13.  
  14. DO
  15.     CLS
  16.     DO
  17.         INPUT "Enter spread probability (between 0.0 and 1.0) ==> ", prob!
  18.     LOOP UNTIL prob! > 0 AND prob! < 1
  19.  
  20.     Rows = 70             ' These values assume 350 x 640 EGA graphics mode
  21.     Cols = 80
  22.     RowRpt = 5
  23.     ColRpt = 8
  24.  
  25.     x% = CAINIT(6, VARPTR(CaArray(0)))        'Initialize the system
  26.     CALL CASIZE (Rows, Cols, RowRpt, ColRpt)    'Set the world size
  27.     CALL CACOLOR (UNBURNED)                        'Set the default color
  28.     RANDOMIZE TIMER
  29.  
  30.     CALL CASET(Rows\2, Cols\2, AFIRE)        'Start file in middle of world
  31.     CASHOW                                            'Show the start
  32.  
  33.     DO WHILE INKEY$ = ""                            'Make generations until
  34.         CAGEN                                            ' user wants to stop
  35.     LOOP
  36.  
  37.     CARESET                                            'Reset so we can print
  38.     CLS
  39.     Print "Do it again? ==> ";                    'Try again?
  40.     DO
  41.         Char$ = Ucase$(Input$(1))
  42.     Loop until instr("YN",Char$)
  43. LOOP While Char$ = "Y"
  44.         
  45. END
  46.  
  47.  
  48. FUNCTION CACELL%                                            ' Here is the fire rule
  49.     ThisOne = CaArray(Self)
  50.     IF ThisOne = AFIRE OR ThisOne = CHARRED THEN    'If you're burning or charred
  51.         result = CHARRED                                    '  you'll be charred.
  52.     ELSE                                                          'If you're unburned
  53.         result = UNBURNED
  54.         FOR i = North TO South STEP 2                    '  you have a chance to
  55.             IF CaArray(i) = AFIRE THEN                    '  catch the fire from any
  56.                 IF RND < prob! THEN                        '  burning neighbor.
  57.                     result = AFIRE
  58.                 END IF
  59.             END IF
  60.         NEXT i
  61.     END IF
  62.     CACELL = result
  63. END FUNCTION
  64.  
  65.